package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.ABuildHome;
import com.ruoyi.lock.service.IABuildHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋管理Controller
 * 
 * @author arvin
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/lock/home")
public class ABuildHomeController extends BaseController
{
    @Autowired
    private IABuildHomeService aBuildHomeService;

    /**
     * 查询房屋管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:home:list')")
    @GetMapping("/list")
    public TableDataInfo list(ABuildHome aBuildHome)
    {
        startPage();
        List<ABuildHome> list = aBuildHomeService.selectABuildHomeList(aBuildHome);
        return getDataTable(list);
    }
    /**
     * 查询房屋管理列表
     */
    @GetMapping("/list2")
    public TableDataInfo list2(ABuildHome aBuildHome)
    {
        List<ABuildHome> list = aBuildHomeService.selectABuildHomeList(aBuildHome);
        return getDataTable(list);
    }
    /**
     * 查询房屋管理列表
     */
    @GetMapping("/list3")
    public TableDataInfo list3(ABuildHome aBuildHome)
    {
        startPage();
        List<ABuildHome> list = aBuildHomeService.selectABuildHomeList(aBuildHome);
        return getDataTable(list);
    }
    /**
     * 导出房屋管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:home:export')")
    @Log(title = "房屋管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ABuildHome aBuildHome)
    {
        List<ABuildHome> list = aBuildHomeService.selectABuildHomeList(aBuildHome);
        ExcelUtil<ABuildHome> util = new ExcelUtil<ABuildHome>(ABuildHome.class);
        util.exportExcel(response, list, "房屋管理数据");
    }

    /**
     * 获取房屋管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:home:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aBuildHomeService.selectABuildHomeById(id));
    }

    /**
     * 新增房屋管理
     */
    @PreAuthorize("@ss.hasPermi('lock:home:add')")
    @Log(title = "房屋管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ABuildHome aBuildHome)
    {
        return toAjax(aBuildHomeService.insertABuildHome(aBuildHome));
    }

    /**
     * 修改房屋管理
     */
    @PreAuthorize("@ss.hasPermi('lock:home:edit')")
    @Log(title = "房屋管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ABuildHome aBuildHome)
    {
        return toAjax(aBuildHomeService.updateABuildHome(aBuildHome));
    }

    /**
     * 删除房屋管理
     */
    @PreAuthorize("@ss.hasPermi('lock:home:remove')")
    @Log(title = "房屋管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aBuildHomeService.deleteABuildHomeByIds(ids));
    }

    /**
     * 根据用户ID查询用户入住的房间列表
     */
    @GetMapping("/listByUserId/{userId}")
    public AjaxResult getHomeListByUserId(@PathVariable("userId") Long userId)
    {
        List<ABuildHome> list = aBuildHomeService.selectABuildHomeListByUserId(userId);
        return success(list);
    }

    /**
     * 查询用户未入住的房间列表（过滤掉已入住的房间）
     */
    @GetMapping("/listByUserIdruzhu")
    public TableDataInfo getHomeListByUserIdruzhu(ABuildHome aBuildHome)
    {
        List<ABuildHome> list = aBuildHomeService.selectABuildHomeListByUserIdruzhu(aBuildHome);
        return getDataTable(list);
    }
}
